<template>
	<view class="content">
		<!-- <u-form :model="form" ref="form" label-width="160rpx">
			<u-form-item label="联系电话" prop="phone" required  >
				<u-input v-model="form.phone" placeholder="请输入联系电话" @focus="getPhone" type="number" />
			</u-form-item>
			<u-form-item label="面积" prop="area" required>
				<u-input v-model="form.area" placeholder="请输入面积" />
			</u-form-item>
			<u-form-item label="地址" prop="address" required>
				<u-input v-model="form.address" type="textarea" placeholder="请输入地址" />
			</u-form-item>
			<u-form-item label="房屋属性" prop="houseProperty">
				<u-input v-model="form.houseProperty" placeholder="请输入房屋属性" />
			</u-form-item>
			<u-form-item label="租金情况" prop="theRentIs">
				<u-input v-model="form.theRentIs" type="textarea" placeholder="请输入租金情况" />
			</u-form-item>
			<u-form-item label="装修情况" prop="decorateSituation">
				<u-input v-model="form.decorateSituation" type="textarea" placeholder="请输入装修情况" />
			</u-form-item>
			<u-form-item label="转让费情况" prop="transferFee">
				<u-input v-model="form.transferFee" type="textarea" placeholder="请输入转让费情况" />
			</u-form-item>

			<view style="margin-top: 30rpx;margin-bottom: 30rpx;">
				<u-button type="primary" :loading="loading" @click="submit">发布</u-button>
			</view>
		</u-form> -->
		<!-- <uni-forms ref="form" :rules="rules"  :value="form" validate-trigger="bind" >
		
			 <uni-forms-item required label="联系电话" name="phone">
			     <uni-easyinput type="number" v-model="form.phone" placeholder="请输入联系电话" />
			 </uni-forms-item>
			<uni-forms-item required label="面积" name="area">
			    <uni-easyinput type="text" v-model="form.area" placeholder="请输入面积" />
			</uni-forms-item>
			<uni-forms-item required label="地址" name="address">
			    <uni-easyinput type="textarea" v-model="form.address" placeholder="请输入地址" />
			</uni-forms-item>
			<uni-forms-item  label="租金情况" name="theRentIs">
			    <uni-easyinput type="textarea" v-model="form.theRentIs" placeholder="请输入租金情况" />
			</uni-forms-item>
			<uni-forms-item  label="装修情况" name="decorateSituation">
			    <uni-easyinput type="textarea" v-model="form.decorateSituation" placeholder="请输入装修情况" />
			</uni-forms-item>
			<uni-forms-item  label="转让费情况" name="transferFee">
			    <uni-easyinput type="textarea" v-model="form.transferFee" placeholder="请输入转让费情况" />
			</uni-forms-item>
			<view style="margin-top: 30rpx;padding-bottom: 30rpx;">
				<u-button type="primary" :loading="loading" @click="submit('form')">发布</u-button>
			</view>
			</uni-forms> -->
			<uni-forms :modelValue="loginForm" ref="loginForm" :rules="loginRules" validate-trigger="bind" >
			      <uni-forms-item name="phone" label="手机号">
			            <uni-easyinput type="text" v-model="loginForm.phone" placeholder="点击输入手机号"></uni-easyinput>
			       </uni-forms-item>
			       <uni-forms-item name="pwd" label="密码">
			            <uni-easyinput type="text" v-model="loginForm.pwd" placeholder="点击输入密码"></uni-easyinput>
			       </uni-forms-item>
			</uni-forms>
			<view style="margin-top: 30rpx;padding-bottom: 30rpx;">
				<u-button type="primary" :loading="loading" @click="submit('loginForm')">发布</u-button>
			</view>
		<u-modal v-model="show" content="确定要发布吗?" @confirm="confirm" show-cancel-button></u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		freeDistribution
	} from "@/services/rental.js"
	import UniForms from "@/components/uni-forms/uni-forms"
	import UniFormsItem from "@/components/uni-forms-item/uni-forms-item"
	import UniEasyinput from "@/components/uni-easyinput/uni-easyinput"
	export default {
		components:{
			UniForms,
			UniFormsItem,
			UniEasyinput
		},
		data() {
			return {
				 loginForm: {
				                    phone: '',
				                    pwd: ''
				                },
				                // 密码登录校验规则
				                loginRules: {
				                    phone: {
				                        rules: [{
				                            required: true,
				                            errorMessage: '请输入手机号码'
				                        }]
				                    },
				                    pwd: {
				                        rules: [{
				                            required: true,
				                            errorMessage: '请输入密码'
				                        }]
				                    }
				                },
				form: {
					phone: '',
					area: '',
					address: '',
					houseProperty: '',
					theRentIs: '',
					decorateSituation: '',
					transferFee: '',
				},
				default: {
					area: '',
					address: '',
					houseProperty: '',
					theRentIs: '',
					decorateSituation: '',
					transferFee: '',
					phone: ''
				},
				loading: false,
				show:false,
				rules: {
					area: {
						rules:[{
							required: true,
							errorMessage: '请输入面积',
							// trigger: ['blur', 'change']
						},
						{
							max: 255,
							errorMessage: '最多255个字符',
							// trigger: ['blur', 'change']
						},]
					},
					address: {
						
						rules:[{
							required: true,
							errorMessage: '请输入地址',
							// trigger: ['blur', 'change']
						},
						{
							max: 255,
							errorMessage: '最多255个字符',
							// trigger: ['blur', 'change']
						},]
						
					},
					phone: {
						rules:[{
							required: true,
							errorMessage: '请输入电话号码',
							// trigger: ['blur', 'change']
						},
						// {
						// 	validateFunction: (rule, value, callback) => {
						// 		// 上面有说，返回true表示校验通过，返回false表示不通过
						// 		// this.$u.test.mobile()就是返回true或者false的
						// 		if (!(/^1[3456789]\d{9}$/.test(value))) {
						// 			return callback(new Error('请输入正确的电话号码'));
						// 		} else {
						// 			callback();
						// 		}
						// 	},
						// },
						]
					},
				},
			};
		},
		onReady() {
			// console.log(this.$refs.form)
			this.$refs.loginForm.setRules(this.rules);
		},
		onShow(){
			this.loading = false
		},
		methods: {
			submit(form) {
				
					// this.form.phone = ""
                   console.log(1)
				   console.log(this.loginForm)
				this.$refs[form].validate().then(res=>{
				                console.log('表单数据信息：', res);
				            }).catch(err =>{
				                console.log('表单错误信息：', err);
				            })
			},
			getPhone(){
				 console.log(1)
			},
			async confirm(){
				this.loading = true
				let res = await freeDistribution({
					formData: this.form,
				
				})
				if (res.code == 200) {
					this.form = this.default
					this.$refs.uToast.show({
						title: '发布成功',
						type: 'success',
						duration:1500,
						callback:function(){
							uni.navigateTo({
								url:'../mine/MySchedule'
							})
						}
					})
					
				}
				this.loading = false
			}
		}
        

	};
</script>
<style scoped lang="less">
	.content {
		background: white;
		padding: 20rpx 20rpx 0 30rpx;
		min-height: 100vh;
	}
</style>
